package com.east.sng.service.impl;

import com.east.sng.dao.RoleDao;
import com.east.sng.entity.param.RoleParam;
import com.east.sng.entity.result.RoleFind;
import com.east.sng.entity.result.RoleInfo;
import com.east.sng.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author east
 * @date: 2021/1/5
 * @Description:
 **/
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleDao roleDao;

    @Override
    public List<RoleInfo> findRoles(Integer flag) {
        return this.roleDao.selectRoles(flag);
    }

    @Override
    public RoleFind findRole(Integer roleId) {
        return this.roleDao.selectRole(roleId);
    }

    @Override
    public void addRole(RoleParam role) {
        this.roleDao.insertRole(role);
    }

    @Override
    public void editRole(RoleParam role) {
        this.roleDao.updateRole(role);
    }

    @Override
    public boolean removeRole(Integer roleId) {
        return this.roleDao.deleteOrRecoverRole(roleId,1)>0;
    }

    @Override
    public boolean recoverRole(Integer roleId) {
        return this.roleDao.deleteOrRecoverRole(roleId,0)>0;
    }

    @Override
    public boolean batchRemoveRoles(List<Integer> roleIds) {
        return this.roleDao.batchDeleteOrRecoverRoles(roleIds,1)>0;
    }

    @Override
    public boolean batchRecoverRoles(List<Integer> roleIds) {
        return this.roleDao.batchDeleteOrRecoverRoles(roleIds,0)>0;
    }

    @Override
    public boolean assignRoleToMenu(Integer roleId, List<Integer> menuIds) {
        this.roleDao.deleteRoleAssignMenus(roleId);
        return this.roleDao.insertRoleAssignMenus(roleId,menuIds)>0;
    }

    @Override
    public List<Map<String, String>> findRoleColumns() {
        return this.roleDao.selectRoleColumns();
    }

    @Override
    public String findRoleCode(Integer roleId) {
        return this.roleDao.selectRoleCode(roleId);
    }

    @Override
    public List<String> findMenuCodes(Integer roleId) {
        return this.roleDao.selectMenuCodes(roleId);
    }
}
